﻿namespace SLClient.Resource.Converters
{
    using System;
    using System.Globalization;
    using System.Text;
    using System.Windows.Data;

    public class StringToCharConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            StringBuilder builder = new StringBuilder();
            if (value != null)
            {
                string str = value.ToString();
                if ((parameter.ToString() == "right") && (str.Length >= 4))
                {
                    builder.Append("*************");
                    str = str.Substring(str.Length - 4, 4);
                    builder.Append(str);
                }
                if (!(parameter.ToString() == "left"))
                {
                    return builder;
                }
                if (str.Length >= 1)
                {
                    str = str.Substring(0, 1);
                    builder.Append(str);
                    builder.Append("********");
                }
            }
            return builder;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

